#pragma once
#include<iostream>
#include<pthread.h>

namespace MutexMod
{
    class Mutex{
    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex,NULL);
        }

        void lock()
        {
            pthread_mutex_lock(&_mutex);
        }
        void unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }

        pthread_mutex_t* getmutex()
        {
            return &_mutex;
        }

        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
    private:
    pthread_mutex_t _mutex;
    };

    class SimpleMutex
    {
        public:
            SimpleMutex(Mutex& mutex)
            :_mutex(mutex)
            {
                _mutex.lock();
            }

            ~SimpleMutex(){
                _mutex.unlock();
            }
        private:
            Mutex& _mutex;
    };
}
